// 暴力解法，利用hash表统计分析
fn rs_main1(str1: String, str2: String) -> bool {
  use std::collections::HashMap;
  if str1.len() != str2.len() {
    return false;
  }
  let mut map = HashMap::new();
  for char1 in str1.chars() {
    let count =  map.entry(char1).or_insert(0);
    *count += 1;
  }
  for char2 in str2.chars() {
    let count =  map.entry(char2).or_insert(0);
    *count -= 1;
    if *count < 0 {
      return false;
    }
  }
  return true;
}

// 暴力解法，利用字符的 ASCII码 建立数组分析
fn rs_main2(str1: String, str2: String) -> bool {
  if str1.len() != str2.len() {
    return false;
  }
  let mut table: [i32; 26] = [0; 26];
  let start_code = 'a' as usize;
  for char1 in str1.chars() {
    table[char1 as usize - start_code] += 1;
  }
  for char2 in str2.chars() {
    let index = char2 as usize - start_code;
    table[index] -= 1;
    if table[index] < 0 {
      return false;
    }
  }
  return true;
}


fn main() {
  println!("{:}", rs_main1(String::from("anagram"), String::from("nagaram")));
  println!("{:}", rs_main1(String::from("rat"), String::from("cat")));
  println!("{:}", rs_main2(String::from("anagram"), String::from("nagaram")));
  println!("{:}", rs_main2(String::from("rat"), String::from("cat")));
}
